package metier;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

public class Vehicule implements Serializable{
	protected int id;
	protected List<Reservation> listeReservation;
	protected static int IDENT_AUTO = 0;
	protected double coefficient;
	protected TypeVehicule type;
	
//
//	public Vehicule() {
//		this.id = IDENT_AUTO++;
//		listeReservation = new ArrayList<Reservation>();	
//	}
	
	public Vehicule(TypeVehicule tv) {
		this.id = IDENT_AUTO++;
		this.type = tv;
		listeReservation = new ArrayList<Reservation>();
		initialisationCoef();
	}
	
	public List<Reservation> getListeReservation() {
		return listeReservation;
	}
	
	public TypeVehicule getType() {
		return type;
	}

	public Reservation reserver(Date dateDepart, Date dateArrivee, AgenceItf agenceDepart,AgenceItf agenceArrivee) {
		Reservation resa = new Reservation(dateDepart, dateArrivee, agenceDepart,  agenceArrivee);
		listeReservation.add(resa);	
		return resa;
	}
	
	public boolean libererVehicule(Reservation reservation){
		return listeReservation.remove(reservation);
	}
	
	public int getId(){
		return id;
	}
	
	public double getCoefficient(){
		return coefficient;
	}
	
	public void initialisationCoef() {
		Properties prop = new Properties();
		prop.clear();
		
		try {
			FileInputStream in = new FileInputStream("agence.properties");
			prop.load(in);
			
			if(this.type.equals(TypeVehicule.AVION)) {
				coefficient = Double.parseDouble((String) prop.get("coefAvion"));
			} 
			else if(this.type.equals(TypeVehicule.BATEAU)) {
				coefficient = Double.parseDouble((String) prop.get("coefBateau"));
			}
			else if(this.type.equals(TypeVehicule.CAMION)) {
				coefficient = Double.parseDouble((String) prop.get("coefCamion"));
			}
			
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}